package Work1;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;
import org.junit.Test;

public class TestSpeed {
	
	@Test
	public void testwrite1() {
		int count=10000*1000;
		PrintWriter out=null;
		try {
			out = new PrintWriter("d:/d.txt");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		for (int i = 0; i < count; i++) {
			out.println(i);
		
		}
		out.close();
	}
	@Test
	public void testwrite2() throws FileNotFoundException {
		int count=10000*1000;
		BufferedWriter out=null;
		try {
			out = new BufferedWriter(new FileWriter("d:/b.txt"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (int i = 0; i < count; i++) {
			try {
				out.write(i);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		try {
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void testread1(){
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(new File("d:/d.txt")));
			while(br.readLine()!=null){
				
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	@Test
	public void testread2(){
		Scanner in=null;
		try {
			 in= new Scanner(new FileReader("d:/d.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		while(in.hasNextLine()){
			in.nextLine();
		}
	}
}
